home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk2 / undel1 / notes < prev    next >
Encoding:
Internet Message Format  |  1995-03-18  |  3.7 KB

  1. From: page@ulowell.cs.ulowell.edu (Bob Page)
  2. Subject: Writing UnDelete (was Gripe about disksalv/diskdoctor)
  3. Date: 5 Jan 88 20:50:34 GMT
  4. Organization: University of Lowell, Computer Science Dept.
  5. Summary: Here's a couple of ways to recover files & data
  6.  
  7.  
  8. peter@sugar.UUCP (Peter da Silva) writes:
  9. >Anyone interested in doing an "Undelete" program?
  10.  
  11. haitex@pnet01.cts.com (Wade Bickel) responds:
  12. >Got a spec. for how you think this program should function?  I need
  13. >to learn about the file system and this seems like a short project, so
  14. >I might be interested.
  15.  
  16. [rolling up his sleeves...]
  17.  
  18. The first thing to do is have the AmigaDOS Technical Ref Manual.  The
  19. second thing to do is learn how the DOS name hashing works.  Get Fish
  20. Disk 20 (the one with DiskSalv) for an example program that does DOS
  21. hashing.
  22.  
  23. OK, now.  Two methods for writing UNDELETE...
  24.  
  25. First.  The easy, fast way to 'undelete' is to scan the disk, block by
  26. block, looking for a file header block that:
  27.  
  28.    a. Has the right file name (it's a BCPL string in the block)
  29.  
  30.    b. Has a 'parent pointer' that points to the right parent
  31.       (you want file proj/src/readme, not proj/doc/readme, right?)
  32.  
  33. Found it?  Good, remember the block number.  Now go to the parent
  34. directory (or what will be the parent directory when you undelete it),
  35. hash the filename, and put the file's block number in the longword
  36. that you just computed.  If the existing longword is not zero, you
  37. have to add the block number to the hash chain.  See the AmigaDOS TRM
  38. for info.
  39.  
  40. There!  You've just done an UNDELETE.  Pretty easy, eh?
  41.  
  42. Second.  Maybe you're not sure all the data is intact.  If you've done
  43. any writing to the disk, this might be the case.  In that case, here's
  44. two ways to get the data back.  You should probably do both, since one
  45. of them might not work.
  46.  
  47. 1. Find the first data block, save the data (the first 24 bytes or six
  48.    longwords are not data), and look at the 'next data block' longword
  49.    to get the next one.  Follow the chain until it ends.  Each data block
  50.    has a serial number, you could check that if you think it would be
  51.    useful.
  52.  
  53. 2. Look at the block list in the file header block, and get each data
  54.    block by its block number (contained in the block list).  If there
  55.    is an extension block (also called file list block), read that
  56.    block for another list of blocks to read.
  57.  
  58. That's all there is to it!  This method of data recovery is what
  59. DiskSalv/DiskDoctor does, except they do it for the whole disk, know
  60. about directories, and other FS gobbly-gook.  Do it for just one file
  61. and you have FileSalv.  <poof>
  62.  
  63. Sanity checks when looking at data blocks:
  64.    a. Make sure it's a data block!  The first longword should be T_DATA
  65.       (something like decimal 8 ... see disksalv.c for the right value,
  66.       or Leo's bm.c, or something similar).
  67.    b. Each data block has a pointer to the file header block.
  68.       If the number doesn't match, something's wrong.
  69.    c. Make sure you don't automatically save 488 bytes per block, some
  70.       locks (like the last one) might not have that much data.  Check
  71.       the longword that tells you how much data there is in the block.
  72.  
  73. Two disclaimers:
  74.  
  75. 1. This is off the top of my head.  No flames if I've forgotten something.
  76.  
  77. 2. These techniques may not work with new versions of the file system.
  78.    FileSalv method 1 (follow the data block chain) will NOT WORK with
  79.    the new (aka fast or HD) file system, since data blocks are always
  80.    512 bytes.  You also have to worry about the new features... :-)
  81.  
  82. ..Bob (still working on the Amiga FS handbook)
  83. --
  84. Bob Page, U of Lowell CS Dept.  page@ulowell.edu  ulowell!page
  85. "I've never liked reality all that much, but I haven't found a
  86. better solution."               --Dave Haynie, Commodore-Amiga
  87.  
  88.